home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
ddj1291.zip
/
STAT.ZIP
/
SOURCE.ZIP
/
PADISPLY.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-05-09
|
8KB
|
220 lines
/* File: padisply.c
**
** Copyright 1990
** Fred Motteler and Applied Microsystems Corporation
** All Rights Reserved
**
** Description: Simple page oriented result display routines.
*/
#include <stdio.h>
#include <string.h>
#include "padef.h"
/*
** Function: int pa_printf(char *linebufS, FILE *outfileFP,
** int *pagelinesNP, int line_countN)
*/
int
pa_printf(linebufS, outfileFP, pagelinesNP, line_countN)
char *linebufS; /* String to display */
FILE *outfileFP; /* Output file pointer, NULL if no file */
int *pagelinesNP; /* Pointer to the number of lines per page,
* 0 if continuous, -1 if no display output,
* n if n lines. */
int line_countN; /* Current page line_countN */
{
int tempcharN; /* Character returned by user */
/* Write the string to the output file if desired */
if (outfileFP != (FILE *) NULL)
fprintf(outfileFP, linebufS);
/* Write the string to the display if desired */
if (*pagelinesNP != (-1))
{
printf(linebufS);
/* Check if the line contains a newline. If so, then increment
* the value of line_countN. */
if (strchr(linebufS, '\n') != (char *) NULL)
line_countN++;
/* Check if at the end of the page. */
if (line_countN >= *pagelinesNP)
{
printf("Press <Enter> for more, Q or q to quit");
tempcharN = getch();
/* Check if user is done looking at display */
if ((tempcharN == 'Q') || (tempcharN == 'q'))
*pagelinesNP = (-1); /* If so, don't display any more */
printf("\n");
line_countN = 0;
}
}
return(line_countN);
}
/*
** Function: void padisplay( struct padata **bintabP, int processedN,
** int pagelinesN, FILE *outfileFP)
**
** Description: This function displays the results of the statistical
** performance analysis. The results are contained in the padata
** structures pointed to in the table pointed to by bintabP.
** Up to the first processedN structures are displayed, unless
** a structure with a zero "hit" count is found. The display
** stops at the first zero hit count.
**
** pagelinesN gives the number of lines to display before waiting
** for a <CR> to continue.
**
** pagelinesN 0 continuous output (no page breaks)
** -1 no output
** n number of lines to display
**
** outfileFP points to an optional output file for the results.
** Note that if pagelinesN = -1 and outfileFP is a valid output
** file pointer, that all output will go to the file.
**
** The results are printed in the following form:
**
** Module table sorted by sample counts:
** ssss samples collected
** module samples % 0 1 2 3 4 5 6 7 8 9 10
** module_1_name ll xx ********************************
** module_2_name mm yy ****************************
** module_3_name nn zz ***************
** etc... .. .. ...
**
** where:
** ssss total number of samples in all modules
** ll number of samples in "module_1_name"
** xx percent of total samples in "module_1_name"
**
** The row of astricks gives a rough visual display of the percentage of
** the total samples in the corresponding module.
*/
void
padisply(bintabP, processedN, pagelinesN, outfileFP)
struct padata **bintabP; /* Pointer to a table of pointers to padata
* data structures, these structures actually
* contain the function name, address, and
* number of program counter hits. */
int processedN; /* Number of entries in the pointer table. */
int pagelinesN; /* Select no. of lines/page, 0 = continuous,
* -1 = quit display */
FILE *outfileFP; /* Output file if not NULL */
{
int i,j; /* general indices */
long max_hitsL; /* Maximum number of hits in any single bin */
long total_hitsL; /* Total number of hits in all bins */
int percentN; /* Percent of total hits in any single bin */
long round_factorL; /* 0.5% of total number of hits in all bins,
* this is used to allow rounding instead of
* truncation. */
int max_percentN; /* Maximum percentage in any single bin */
int max_axisN; /* Maximum percentage displayed on axis */
int astricksN; /* Number of astricks to print on line */
int line_countN; /* Number of lines on current page, error code
* if negative. */
char linebufAB[PA_LINE_LEN]; /* staging buffer for output lines */
/* Search for maximum hit count. Also, find the total number of hits. */
max_hitsL = 0L;
total_hitsL = 0L;
for (i = 0; i < processedN; i++)
{
if (((bintabP[i])->hitsL) == 0L)
break;
if (((bintabP[i])->hitsL) > max_hitsL)
max_hitsL = (bintabP[i])->hitsL;
total_hitsL += (bintabP[i])->hitsL;
}
round_factorL = total_hitsL / 200L; /* Get 0.5% of total number of hits. */
max_percentN = ((max_hitsL + round_factorL) * 100L) / total_hitsL;
line_countN = 0;
sprintf(linebufAB, "Module table sorted by sample counts:\n");
line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN, line_countN);
sprintf(linebufAB, "%ld samples collected\n", total_hitsL);
line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN, line_countN);
/* Determine scale along axis to print out, and appropriate scaling
* factor. */
sprintf(linebufAB, " module samples % ");
line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN, line_countN);
if (max_percentN <= 10)
{
max_axisN = 10;
sprintf(linebufAB,
"0 1 2 3 4 5 6 7 8 9 10\n");
line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN,
line_countN);
}
else if (max_percentN <= 20)
{
max_axisN = 20;
sprintf(linebufAB,
"0 2 4 6 8 10 12 14 16 18 20\n");
line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN,
line_countN);
}
else if (max_percentN <= 30)
{
max_axisN = 30;
sprintf(linebufAB,
"0 5 10 15 20 25 30\n");
line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN,
line_countN);
}
else if (max_percentN <= 50)
{
max_axisN = 50;
sprintf(linebufAB,
"0 5 10 15 20 25 30 35 40 45 50\n");
line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN,
line_countN);
}
else if (max_percentN <= 100)
{
max_axisN = 100;
sprintf(linebufAB,
"0 10 20 30 40 50 60 70 80 90 100\n");
line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN,
line_countN);
}
/* Display the data */
for (i = 0; i < processedN; i++)
{
/* Quit at first bin with zero hits. */
if (((bintabP[i])->hitsL) == 0L)
break;
/* Calculate the percent of hits in the bin. Include adding in a
* constant that allows rounding instead of truncation to the nearest
* percent. */
percentN =
((((bintabP[i])->hitsL) + round_factorL) * 100L) / total_hitsL;
/* Print the module name, the actual number of hits, and the percent */
sprintf(linebufAB, "%16s %5ld %3d ",
((bintabP[i])->symbolAB),
((bintabP[i])->hitsL),
percentN);
line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN,
line_countN);
/* Print a row of astricks proportional to the percent */
astricksN = (percentN * 52) / max_axisN;
for (j = 0; j < astricksN; j++)
{
sprintf(linebufAB, "*");
line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN,
line_countN);
}
sprintf(linebufAB, "\n");
line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN,
line_countN);
}
return;
}